-
Notifications
You must be signed in to change notification settings - Fork 73
fix: use safe-decode-uri-component #450
fix: use safe-decode-uri-component #450
Conversation
This takes care of file names with `'%'` character. File names like these can be automatically created by IDEs for backup. Also, added a test for adding file with `'%'` character to `InMemoryFileSystem`. Fixes sourcegraph#422
@@ -9,6 +9,7 @@ | |||
"sourceMap": true, | |||
"declaration": true, | |||
"strictFunctionTypes": false, | |||
"esModuleInterop": true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this because safe-decode-uri-component
is written in CommonJS. With this flag safe-decode-uri-component
can be imported by:
import safeDecodeURIComponent from 'safe-decode-uri-component'
rather than
import * as safeDecodeURIComponent from 'safe-decode-uri-component'
@@ -18,6 +18,14 @@ describe('memfs.ts', () => { | |||
sinon.assert.calledOnce(listener) | |||
sinon.assert.calledWithExactly(listener, 'file:///foo/bar.txt', undefined) | |||
}) | |||
it('should add a URI with `%` character and emit an event', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test would have been failed before this PR changes.
This is exactly the case #422 referres to.
Since esModuleInterop set to true, `rimraf` can be imported like a regular module
@@ -2,7 +2,7 @@ import * as chai from 'chai' | |||
import chaiAsPromised = require('chai-as-promised') | |||
import * as fs from 'mz/fs' | |||
import * as path from 'path' | |||
import * as rimraf from 'rimraf' | |||
import rimraf from 'rimraf' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codecov Report
@@ Coverage Diff @@
## master #450 +/- ##
==========================================
+ Coverage 83.18% 83.19% +<.01%
==========================================
Files 15 15
Lines 2040 2041 +1
Branches 415 415
==========================================
+ Hits 1697 1698 +1
Misses 341 341
Partials 2 2
Continue to review full report at Codecov.
|
Reading the code, it appears to me this only fixes the issue for file names with invalid escapes. If you modify your test to use a valid escape in the file name, would it still pass? |
Do you mean |
I meant a file that is literally called |
oh, I see what you mean. I made this PR to fix #422 (where for some reason paths are not escaped properly) in order to prevent a fatal exception. |
Okay, in that case I believe the issue should be fixed properly. |
Do you want to close the PR? |
Sorry for bluntly chime in. #422 is not caused by invalid encoding. The file name is literally As I also commented under #422, language client didn't send this path. It is picked up by language server when trying to build index. With that said, this should resolve #422, though it only fixes the consequeue but not the cause. I'd love to see #422 got resolved, but a concern from this project's perspective is that how much compatibility this new |
@autozimu Thanks for the explanation. @felixfbecker @autozimu Thanks for your input and attention. |
For context, the reason why the code calls Now the bug here seems to be indeed that the URI for |
The call comes from
The result come from glob should already be valid paths. For the concern that the path might have other aliases other than its canonical form. I believe it can be done by querying from filesystem, https://github.com/autozimu/LanguageClient-neovim/blob/84445be4a3bf7f67547abad205c6c46eb289844d/src/languageclient.rs#L1619 It won't cover all cases, but should be enough for general cases. |
Oh, seems like all it needs it to encode
That won't work because not all files the language server works with are available on the file system. |
This takes care of file names with
'%'
character. File names likethese can be automatically created by IDEs for backup.
Also, added a test for adding file with
'%'
character toInMemoryFileSystem
.Fixes #422